package com.groupbuying.sysconfig.controller.ali;


import com.groupbuying.sysconfig.service.ali.AliAuthLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Description: 支付宝用户授权认证和授权手机号解密信息接口
 * @Auther: yangmeng
 * @Date: 2019/10/16 8:44
 **/
@RestController
@RequestMapping("/aliMiniApp")
public class AliAuthLoginController {

    @Autowired
    private AliAuthLoginService aliAuthLoginService;

    /**
     * @api {get} /aliMiniApp/aliGetUserIdAccessCodeByAuthCode 用户认证授权获取alipayUserId和accessToken接口
     * @apiExample
     * author yangmeng
     * tar 用于api内部调用
     * date 2019/10/31 14:31
     * @apiGroup service-sysconfig
     * @apiVersion 1.0.0
     * @apiHeader {String} Authorization 用户授权token
     * @apiParam {String} authCode 支付宝用户授权code
     * @apiParam {String} indicate 唯一应用标识
     * @apiSuccess {String} alipayUserId 支付宝用户的唯一userId
     * @apiSuccess {String} accessToken 访问令牌。通过该令牌调用需要授权类接口
     */
    @GetMapping("/aliGetUserIdAccessCodeByAuthCode")
     public Map<String, String> aliGetUserIdAccessCodeByAuthCode (@RequestParam("authCode") String authCode, @RequestParam("indicate") String indicate) throws Exception {
        return aliAuthLoginService.aliGetUserIdAccessCodeByAuthCode(authCode);
    }

    /**
     * @api {post} /aliMiniApp/aliDecodeUserEncryptedData 支付宝用户授权手机号解密信息接口
     * @apiExample
     * author yangmeng
     * tar 用于api内部调用
     * date 2019/10/31 14:33
     * @apiGroup service-sysconfig
     * @apiVersion 1.0.0
     * @apiHeader {String} Authorization 用户授权token
     * @apiParam {String} encryptedData 支付宝用户授权手机号加密信息
     * @apiSuccess {String} encryptedData 支付宝用户授权手机号加密信息
     */
    @PostMapping("/aliDecodeUserEncryptedData")
    public Map<String, String> aliDecodeUserEncryptedData (@RequestParam Map<String, String> params) {
        return aliAuthLoginService.aliDecodeUserEncryptedData(params);
    }
}
